package com.leedcode;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * https://leetcode-cn.com/problems/move-zeroes/
 * @author andy
 * @version 1.0
 * @date 2021-12-22 10:07 上午
 */
public class Ld283 {
    public void moveZeroes(int[] nums) {
        int n = nums.length;
        int j = 0;  // [0, j) 元素均为非0元素

        for (int i = 0; i < n; i++) {
            if (nums[i] != 0) {
                int temp = nums[j];
                nums[j] = nums[i];
                nums[i] = temp;
                j++;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {0,1,0,3,12};
        (new Ld283()).moveZeroes(arr);
        for (int i : arr) {
            System.out.println(i);
        }
    }
}
